/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.gateway.dianlan.processor.business;

import info.peigen.hotpot.component.gateway.dianlan.annotations.DianlanProtocolParse;
import info.peigen.hotpot.component.gateway.dianlan.facade.enums.DianlanFrameSign;
import info.peigen.hotpot.component.gateway.dianlan.processor.AbstractDianlanProcessor;
import info.peigen.hotpot.component.gateway.dianlan.protocol.Dianlan;
import info.peigen.hotpot.component.gateway.dianlan.protocol.passive.DianlanBillingModelCheck;
import info.peigen.hotpot.component.gateway.dianlan.protocol.passive.DianlanBillingModelCheckResponse;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.StateMachineEnum;
import org.smartboot.socket.transport.AioSession;

/**
 * <b>(DianlanBiilingModelCheckProcessor)</b>
 *
 * @author czj
 * @version 1.0.0
 * @since 2023/2/9
 */
@Component("dianlanBiilingModelCheckProcessor")
@Slf4j
public class DianlanBiilingModelCheckProcessor<T> extends AbstractDianlanProcessor implements MessageProcessor<T> {

    @Override
    public void process(AioSession session, Object obj) {
        Dianlan                  dianlan = (Dianlan) obj;
        DianlanBillingModelCheck check   = DianlanProtocolParse.deserialization(dianlan.getData(), DianlanBillingModelCheck.class);
        DianlanBillingModelCheckResponse response = DianlanBillingModelCheckResponse.builder()
                .stubNo(check.getStubNo())
                .billingModelNo(check.getBillingModelNo())
                .billingModelCheckResponse("00")
                .build();
        dianlan.setFrameSign(DianlanFrameSign.BillingModelCheckResponse);
        response(dianlan, response);
        write(session, dianlan);
    }

    @Override
    public void stateEvent(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) {
        MessageProcessor.super.stateEvent(session, stateMachineEnum, throwable);
    }
}